package com.facotry.service.Impl;

import com.facotry.entity.FacUser;
import com.facotry.entity.ProducePlan;
import com.facotry.mapper.ProducePlanMapper;
import com.facotry.service.ProducePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * ------ 天道酬勤 -------
 *
 * @author ChenZihao
 * @date 2024/7/24
 * @desc --- 代码敲烂 月薪过万 ---
 */

@Service
public class ProducePlanServiceImpl implements ProducePlanService {
    @Autowired
    private ProducePlanMapper producePlanMapper;


    @Override
    public List<ProducePlan> findAll(HashMap<String,String> map) {
       List<ProducePlan> list =  producePlanMapper.findAll(map);
        return list;
    }

    @Override
    public boolean addProducePlan(ProducePlan producePlan) {

        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        FacUser info = (FacUser) request.getSession().getAttribute("userInfo");
        String username = info.getUsername();
        producePlan.setCreater(username);
        producePlan.setCreateTime(new Date());
        boolean isOk = producePlanMapper.addProducePlan(producePlan);

        return isOk;
    }

    @Override
    public int delBatchPlans(List<String> list) {
        int i = producePlanMapper.delBatchPlans(list);
        return i;
    }

    @Override
    public boolean delPlanByNum(String num) {
        boolean isOk = producePlanMapper.delPlanByNum(num);
        return isOk;
    }

    @Override
    public boolean editPlan(ProducePlan producePlan) {
        boolean isOk = producePlanMapper.editPlan(producePlan);
        return isOk;
    }

    @Override
    public boolean editManagePlan(ProducePlan producePlan) {
        producePlan.setPlanState("plan");
        boolean isOk = producePlanMapper.editManagePlan(producePlan);
        return isOk;
    }
}
